﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/App.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="Ornament.MemberShip.Permissions" %>
<%@ Import Namespace="Ornament" %>
<%@ Import Namespace="Qi" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    创建许可
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/C#" runat="server">
        protected string GetOperationsExpress(Permission pe)
        {
            var directory = EnumHelper.GetDescriptionList<Enum>();
            var operators = new string[directory.Count];
            var idx = 0;
            foreach (var key in directory.Keys)
            {
                operators[idx] = Convert.ToInt32(directory[key]) != 0 && pe.HasOperator(directory[key]) ? "[" + key + "]" : key;
                idx++;
            }
            return String.Join(",", operators);
        }

    </script>
    <h2>
        创建许可</h2>
    <div class="buttonContainer">
        <a id="add" href="<%=Url.Action("Create")%>">添加</a>
    </div>
    <table id="permissionList" style="width: 750px" class="table">
        <thead>
            <tr>
                <th style="width: 80px">
                </th>
                <th>
                    资源类型
                </th>
                <th>
                    名称
                </th>
                <th>
                    说明
                </th>
                <th>
                    操作集合
                </th>
            </tr>
        </thead>
        <%            
            foreach (Permission pe in (IQueryable<Permission>)ViewData["permissions"])
            {       
                
        %>
        <tr>
            <td>
                <a href="<%=Url.Action("Create",new {Id=pe.Id}) %>">编辑</a> <a href="<%=pe.Id %>"
                    class="delete">删除</a>
            </td>
            <td>
                <%=pe.Resource %>
            </td>
            <td>
                <%=pe.Name %>
            </td>
            <td>
                <%=pe.Remark %>
            </td>
            <td>
                <%=GetOperationsExpress(pe)%>
            </td>
        </tr>
        <%} %>
    </table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">

        $(document).ready(function () {

            $(".delete").live('click', function () {
                if (confirm("是否删除本项内容")) {
                    var target = $(this);
                    $.getJSON('<%=Url.Action("Delete")%>/' + target.attr("href"), {}, function (result) {
                        oAlert(result.Message);
                        if (result.Success) {
                            target.parent().parent().remove();
                        }
                    });
                }
                return false;
            });

            $("#add").button();
        });
      
    </script>
</asp:Content>
